package com.ay.weixin.fdc.front.usercenter.event;

import java.io.IOException;

import javax.servlet.ServletException;

import org.lizar.config.keys.Keys;
import org.lizar.controller.Event;
import org.lizar.controller.loader.EventLoader;
import org.lizar.ioc.Container;
import org.lizar.util.StringHelper;

import com.ay.weixin.config.types.UserType;
import com.ay.weixin.fdc.boss.user.domain.FDCAgent;
import com.ay.weixin.fdc.boss.user.domain.FDCUserCenter;

public class Logout extends Event {

	private FDCUserCenter user_center;
	
	@Override
	public void init_property() throws Exception {
		user_center=Container.get(FDCUserCenter.class);
	}

	@Override
	public String default_handling_path() {
		return "/fdc/logout/*";
	}

	@Override
	public void handle(EventLoader el) throws ServletException, IOException {
		long project_id=el.queryPathInt(2);
		System.out.println("project_id:"+project_id);
		
		FDCAgent user=el.getSessionAttr("user",FDCAgent.class);
		el.removeSessionAttr("user");
		user_center.removeSession(user.getId());
		if(user==null||StringHelper.equals(user.getType(), UserType.manager.name())){
			el.response_to_root("/fdc/login/"+project_id);
		}else{
			el.response_to_root("/fdc/login/old/"+project_id);
		}
		
	}

}
